import { defineStore } from "pinia";

export const useAside = defineStore('main', {
    state: () => ({
        // 控制侧边栏收缩按钮
        isCollapse: false,
        // 面包屑数据
        currentMenu:null,
        //侧边栏数据
        tabList:[
            {
                name: 'home',
                path: '/',
                label: '首页',
                icon: 'house',
            },
        ] 
    }),
    actions: {
        // 控制侧边栏收缩方法
        updateIsCollapse(){
            this.isCollapse=!this.isCollapse
        },
        // 更新面包屑数据
        selectMenu(val){
            // console.log(val);
            if(val.name=='home'){
                this.currentMenu=null
            }else{
                this.currentMenu=val
                let res = this.tabList.findIndex(item=>item.name === val.name)
                res === -1 ? this.tabList.push(val) : ''
            }
        },
        //关闭标签
        closeTag(val){
            let res = this.tabList.findIndex(item=>item.name === val.name)
            this.tabList.splice(res,1)
        }
    },
    persist: true,
})